package com.example.chenxiaojun.messagedigestdemo;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class MainActivity extends AppCompatActivity {
private String password="chenxiaojun";
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

    public void messageDigest(View view) {
        switch (view.getId()){
            case R.id.md5:
                messageDigest("MD5",password);
                break;
            case R.id.sha1:
                messageDigest("SHA-1",password);
                break;
        }
    }

    private String messageDigest(String type, String data) {
        try {
            MessageDigest messageDig=MessageDigest.getInstance(type);
            messageDig.update(data.getBytes());
            byte[] digest = messageDig.digest();



        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }


        return null;
    }
}
